Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.x: add Completable.cache() #4930

Merged
merged 1 commit into from
Dec 20, 2016
Merged

Conversation

akarnokd
Copy link
Member

This PR adds the operator cache() to Completable to cache the terminal event of a Completable sequence.

I came across the need for this when answering a question where the intent of using Completable was to indicate an operation has completed but not actually trigger the operation whenever one subscribed.

A small drawback, just like with other cache() operators is that once connected, there is no way for cancel it from within the operator itself. Returning Completable & Disposable doesn't work because of the the type restriction of RxJavaPlugins.onAssembly. There could be a cache(Consumer<? super Disposable> onDispose) overload or an example showing source.ambWith(disposer).cache().

@akarnokd akarnokd added this to the 2.1 milestone Dec 20, 2016
@codecov-io
Copy link

codecov-io commented Dec 20, 2016

Current coverage is 95.62% (diff: 100%)

Merging #4930 into 2.x will decrease coverage by 0.05%

@@                2.x      #4930   diff @@
==========================================
  Files           586        587     +1   
  Lines         37452      37519    +67   
  Methods           0          0          
  Messages          0          0          
  Branches       5627       5644    +17   
==========================================
+ Hits          35833      35877    +44   
- Misses          682        696    +14   
- Partials        937        946     +9   

Powered by Codecov. Last update 9b91d4e...267994f

@akarnokd akarnokd merged commit a902d4a into ReactiveX:2.x Dec 20, 2016
@akarnokd akarnokd deleted the CompletableCache2x branch December 20, 2016 16:51
@PaulWoitaschek
Copy link
Contributor

PaulWoitaschek commented Jan 5, 2017

Great improvement, thanks!

In one of my projects I applied this transformer to a lot of sequences:

private static final CompletableTransformer cache = completable ->
    completable.toObservable()
      .cacheWithInitialCapacity(1)
      .ignoreElements();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants